##########################################################
# John Henderson and Alex Theodoridis
# Replication Data for: "Seeing Spots", 
#  Forthcoming in Political Behavior, August 20, 2017
# 
##########################################################
#
#  figure_5.R 
#  -- file produces the mean bar plots Figure 5 and figure v in appendix
#
##########################################################

rm(list=ls())
source('~/Dropbox/Seeing_Spots/replication/pre_data.R')

ymat=cbind(video_skipped, replay, share, getlink, all_y,time_watched, total_time)   
        
# all party * tone                                                             
pdf(file='~/Dropbox/Seeing_Spots/replication/figures/all_party_tone.pdf')    
par(cex=.8, cex.axis=1., cex.lab=1.)#, tcl=0)
plotmeans(ylim=c(0,2),ylab='Total Ad-Seeking Choices',xlab='',#xlab='Ad Exposure',   
	(all_y)[which(pid_lean!=0)]~interaction(tr_full[which(pid_lean!=0)],pid_lean[which(pid_lean!=0)]), 
	connect=F,mean.labels=TRUE, barwidth=3.15, barcol=c("darkblue","darkblue","darkblue","darkblue","red","red","red","red"), digits=2, 
	legends=c("","","","","","","",""), 
	col=NULL, xaxt=c(2,8,3), n.label=F, ann=T, lwd=1)
legend(x="topleft",
 legend=c("Democrats", "Republicans"),
 col=c("navyblue", "red"), 
 lwd=3.15, 
 bty="n", 
 cex=1, 
 inset=.01)
abline(v=4.5,lty=2)        
ns=t(c(table(interaction(tr_full[which(pid_lean!=0)],pid_lean[which(pid_lean!=0)]))))
axis(cex=.5,1, at=c(1, 2, 3, 4, 5, 6, 7, 8),  
	labels=c(
		paste("\n\nObama\nPositive\n(n=",ns[1],")",sep=''),
		paste("\n\nObama\nNegative\n(n=",ns[2],")",sep=''),
		paste("\n\nRomney\nPositive\n(n=",ns[3],")",sep=''),
		paste("\n\nRomney\nNegative\n(n=",ns[4],")",sep=''),
		paste("\n\nObama\nPositive\n(n=",ns[5],")",sep=''),
		paste("\n\nObama\nNegative\n(n=",ns[6],")",sep=''),
		paste("\n\nRomney\nPositive\n(n=",ns[7],")",sep=''),
		paste("\n\nRomney\nNegative\n(n=",ns[8],")",sep='')
	),padj=.34)
dev.off()
# ...
        

# all party * tone
pdf(file='~/Dropbox/Seeing_Spots/replication/figures/all_party_tone_all.pdf')    
par(cex=.8, cex.axis=.7, cex.lab=1.)#, tcl=0)
plotmeans(ylim=c(0,2),ylab='Total Ad-Seeking Choices',xlab='',#xlab='Ad Exposure',   
	(all_y)~interaction(tr_full,pid_lean), 
	connect=F,mean.labels=TRUE, barwidth=3.15, barcol=c("darkblue","darkblue","darkblue","darkblue","mediumorchid4","mediumorchid4","mediumorchid4","mediumorchid4","red","red","red","red"), digits=2, 
	legends=c("","","","","","","","","","","",""), 
	col=NULL, xaxt=c(2,8,3), n.label=F, ann=T, lwd=1)
legend(x="topleft",
 legend=c("Democrats", "Independents", "Republicans"),
 col=c("navyblue", "mediumorchid4","red"), 
 lwd=3.15, 
 bty="n", 
 cex=1, 
 inset=.01)
abline(v=4.5,lty=2)      
abline(v=8.5,lty=2)        
ns=t(c(table(interaction(tr_full,pid_lean))))
axis(cex=.5,1, at=c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12),  
	labels=c(
		paste("\n\nObama\nPositive\n(n=",ns[1],")",sep=''),
		paste("\n\nObama\nNegative\n(n=",ns[2],")",sep=''),
		paste("\n\nRomney\nPositive\n(n=",ns[3],")",sep=''),
		paste("\n\nRomney\nNegative\n(n=",ns[4],")",sep=''),
		paste("\n\nObama\nPositive\n(n=",ns[5],")",sep=''),
		paste("\n\nObama\nNegative\n(n=",ns[6],")",sep=''),
		paste("\n\nRomney\nPositive\n(n=",ns[7],")",sep=''),
		paste("\n\nRomney\nNegative\n(n=",ns[8],")",sep=''),
		paste("\n\nObama\nPositive\n(n=",ns[9],")",sep=''),
		paste("\n\nObama\nNegative\n(n=",ns[10],")",sep=''),
		paste("\n\nRomney\nPositive\n(n=",ns[11],")",sep=''),
		paste("\n\nRomney\nNegative\n(n=",ns[12],")",sep='')
	),padj=.34)
dev.off()
# ...

# END figure_5_v.R  